#include "rocket_3.h"

ROCKET_3::ROCKET_3(QPoint begin, SCENE *scene, QTimeLine *global_tl, CASH *cash):QGraphicsObject()
{

    shot = new SOUND_POWER(cash,"Res/Sound/Enemy/Enemy_10/shot.ogg",this);
    QTimer::singleShot(12000,shot,SLOT(Play_Now_Slot()));

    this->cash = cash;

    int otklonenie=20;  // Отклонение ракеты от общей точки...

    point=99;

    border = new QPainterPath();
    im = cash->cash_pixmap->value("Res/weapons/rocket_3/rocket_3.png");

    this->setZValue(0.5);

    this->setPos(QPoint(begin.x()+otklonenie,begin.y()));

    anim_rocket = new QGraphicsItemAnimation();

    rocket_time_line = new QTimeLine(15000);
    rocket_time_line->setEasingCurve(QEasingCurve::Type(1));
    rocket_time_line->setFrameRange(0,1);
    anim_rocket->setTimeLine(rocket_time_line);
    anim_rocket->setItem(this);

    anim_rocket->setPosAt(0,QPoint(begin.x()+otklonenie,begin.y()+500));
    anim_rocket->setPosAt(0.1,QPoint(begin.x()+otklonenie,begin.y()+500));
    anim_rocket->setPosAt(0.2,QPoint(begin.x()+otklonenie,begin.y()+500));
    anim_rocket->setPosAt(0.3,QPoint(begin.x()+otklonenie,begin.y()+500));
    anim_rocket->setPosAt(0.4,QPoint(begin.x()+otklonenie,begin.y()+500));
    anim_rocket->setPosAt(0.5,QPoint(begin.x()+otklonenie,begin.y()+500));
    anim_rocket->setPosAt(0.6,QPoint(begin.x()+otklonenie,begin.y()+500));
    anim_rocket->setPosAt(0.7,QPoint(begin.x()+otklonenie,begin.y()+500));
    anim_rocket->setPosAt(0.8,QPoint(begin.x()+otklonenie,begin.y()+500));
    anim_rocket->setPosAt(0.9,QPoint(begin.x()+otklonenie,begin.y()+500));
    anim_rocket->setPosAt(1,QPoint( begin.x()+otklonenie,-500) );

    rocket_time_line->start();

    collisia_control = new COLLISIA_CONTROL(scene,((QGraphicsObject*)this),this,global_tl,cash,100);

    connect(collisia_control,SIGNAL(Collisia(QPointF,int)),this,SLOT(Damage_Detected(QPointF,int)));
    connect(rocket_time_line,SIGNAL(finished()),SLOT(deleteLater()));

    QTimer::singleShot(100, this, SLOT(set_shape()));
}

QPainterPath ROCKET_3::shape() const
{

    return *border;

}

QRectF ROCKET_3::boundingRect() const
{

    return QRectF( QPointF(0,0),im->size() );


}

void ROCKET_3::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
{

    painter->save();
    painter->drawPixmap( 0,0,*im );
    painter->restore();

}

ROCKET_3::~ROCKET_3()
{
    //shot->Stop();
}

int ROCKET_3::type() const
{

    return point;

}

void ROCKET_3::Damage_Detected(QPointF a, int d)
{

    a = QPointF();
    point-=d;

    if(point<=0){
        //shot->Stop();
        this->scene()->removeItem(this);
    }

}

void ROCKET_3::set_shape()
{
    this->border = cash->cash_poly->value("Res/weapons/rocket_3/rocket_3.poly");
}



